/*
 * MIT License
 *
 * Copyright (c) 2025 Mark·虎
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

package com.hsxxherp.key.uia.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hsxxherp.key.support.model.entity.BaseAuditEntity;

import java.time.OffsetDateTime;

/**
 * 应用版本表
 *
 * @author Mark·虎（2486970363@qq.com）
 */
@TableName("sys_application_version")
public class SysApplicationVersion extends BaseAuditEntity {
    /**
     * 版本唯一标识，对应表中的 version_id 字段，作为主键
     */
    @TableId
    private String versionId;

    /**
     * 关联的应用 ID，对应表中的 app_id 字段
     */
    @TableField("app_id")
    private String appId;

    /**
     * 版本号，对应表中的 version_num 字段
     */
    @TableField("version_num")
    private String versionNum;

    /**
     * 版本描述，对应表中的 description 字段
     */
    @TableField("description")
    private String description;

    /**
     * 版本发布时间，对应表中的 release_time 字段
     */
    @TableField("release_time")
    private OffsetDateTime releaseTime;

    /**
     * 版本状态，对应表中的 status 字段
     */
    @TableField("status")
    private VersionStatus status;

    /**
     * 部署状态，对应表中的 deploy_status 字段
     */
    @TableField("deploy_status")
    private DeployStatus deployStatus;

    /**
     * 前一个版本的 ID，对应表中的 prev_version_id 字段，用于回滚操作
     */
    @TableField("prev_version_id")
    private String prevVersionId;

    public String getVersionId() {
        return versionId;
    }

    public void setVersionId(String versionId) {
        this.versionId = versionId;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getVersionNum() {
        return versionNum;
    }

    public void setVersionNum(String versionNum) {
        this.versionNum = versionNum;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public OffsetDateTime getReleaseTime() {
        return releaseTime;
    }

    public void setReleaseTime(OffsetDateTime releaseTime) {
        this.releaseTime = releaseTime;
    }

    public VersionStatus getStatus() {
        return status;
    }

    public void setStatus(VersionStatus status) {
        this.status = status;
    }

    public DeployStatus getDeployStatus() {
        return deployStatus;
    }

    public void setDeployStatus(DeployStatus deployStatus) {
        this.deployStatus = deployStatus;
    }

    public String getPrevVersionId() {
        return prevVersionId;
    }

    public void setPrevVersionId(String prevVersionId) {
        this.prevVersionId = prevVersionId;
    }

    /**
     * 版本状态枚举类
     * 该枚举类定义了应用版本可能的状态，包括已创建、测试中、已发布、已回滚和已归档。
     * 用于在代码中统一管理和使用版本状态，避免硬编码字符串带来的错误。
     */
    public enum VersionStatus {
        /**
         * 已创建
         */
        CREATED("CREATED", "已创建"),
        /**
         * 测试中
         */
        TESTING("TESTING", "测试中"),
        /**
         * 已发布
         */
        PUBLISHED("PUBLISHED", "已发布"),
        /**
         * 已回滚
         */
        ROLLED_BACK("ROLLED_BACK", "已回滚"),
        /**
         * 已归档
         */
        ARCHIVED("ARCHIVED", "已归档");

        private final String code;
        private final String description;

        VersionStatus(String code, String description) {
            this.code = code;
            this.description = description;
        }

        public String getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 部署状态枚举类
     * 该枚举类定义了应用版本部署过程中的可能状态，包括未部署、部署中、已部署和部署失败。
     * 用于在代码中统一管理和使用部署状态，避免硬编码字符串带来的错误。
     */
    public enum DeployStatus {
        NOT_DEPLOYED("NOT_DEPLOYED", "未部署"),
        DEPLOYING("DEPLOYING", "部署中"),
        DEPLOYED("DEPLOYED", "已部署"),
        DEPLOY_FAILED("DEPLOY_FAILED", "部署失败");

        private final String code;
        private final String description;

        DeployStatus(String code, String description) {
            this.code = code;
            this.description = description;
        }

        /**
         * 获取部署状态的代码
         *
         * @return 部署状态代码
         */
        public String getCode() {
            return code;
        }

        /**
         * 获取部署状态的描述信息
         *
         * @return 部署状态描述
         */
        public String getDescription() {
            return description;
        }
    }
}